<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<html>
<head>
	<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta http-equiv="Pragma" content="no-cache">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="format-detection" content="telephone=no" />
	<meta name="apple-mobile-web-app-capable" content="yes" />
	<meta content="black" name="apple-mobile-web-app-status-bar-style">
	<link href="css/bksystem.css" rel="stylesheet" type="text/css" />
	<link href="font/iconfont.css" rel="stylesheet" type="text/css" />
	<link href="css/module.css" rel="stylesheet" type="text/css" />
	<link href="css/pages.css" rel="stylesheet" type="text/css" />
	<title>订单管理</title>
	<script src="js/jquery-1.9.1.min.js" type="text/javascript"></script>
	<script src="js/jquery.nicescroll.js" type="text/javascript"></script>
	<script src="js/HUpages.js" type="text/javascript"></script>
	<script src="js/template.js" type="text/javascript"></script>
	<!--[if lt IE 9]>
	<script src="js/html5shiv.js" type="text/javascript"></script>
	<script src="js/css3-mediaqueries.js"  type="text/javascript"></script>
	<![endif]-->
	<style>
		body {
			font-family: Arial, sans-serif;
			background-color: #F5F5F5;
			margin: 0;
			padding: 20px;
			height: 100%;
		}

		h1 {
			font-weight: bold;
			color: #333;
			margin-bottom: 30px;
		}

		form {
			margin-bottom: 20px;
		}

		label {
			display: inline-block;
			width: 120px;
			text-align: right;
			margin-right: 10px;
			font-weight: bold;
			font-size: 20px;
		}

		input[type="text"],
		select {
			padding: 5px;
			border: 1px solid #999;
			border-radius: 3px;
		}

		input[type="submit"],
		input[type="button"] {
			padding: 8px 16px;
			font-weight: bold;
			background-color: #007BFF;
			color: #FFF;
			border: none;
			border-radius: 3px;
			cursor: pointer;
		}

		table {
			width: 100%;
			border-collapse: collapse;
		}

		th, td {
			padding: 8px;
			border-bottom: 1px solid #DDD;
			text-align: center;
		}

		th {
			background-color: #f2f2f2;
			font-weight: bold;
		}

		tr:nth-child(even) {
			background-color: #f9f9f9;
		}

		.error-message {
			color: red;
			font-weight: bold;
			margin-top: 10px;
		}
		#xj{
			width: 100px;
			height: 60px;
		}
		body {
			overflow-y: scroll;
		}
	</style>
</head>
<body>
<h1>订单管理</h1>
<label for="index">订单编号：</label>
<input type="text" name="index" id="index">
<input type="button" value="搜索" onclick="searchSnacks()">
<table>
	<thead>
	<tr>
		<th>订单编号</th>
		<th>下单时间</th>
		<th>订单号</th>
		<th>客户id</th>
		<th>备注</th>
		<th>取餐方式</th>
		<th>支付方式</th>
		<th>状态</th>
		<th>取餐时间</th>
	</tr>
	</thead>
	<tbody>
	</tbody>


</table>

<div id="pageDiv">
</div>
<script>
	function upa(idStr) {
		var result = confirm("确定将当前订单提交吗?");
		if (result) {
			$.ajax({
				url: "UpdServlet",
				type: "post",
				data:{
					id:idStr,
				},
				success: function (temp) {
					if (parseInt(temp) > 0) {
						alert("提交成功");
						alert("当前订单已完成")
						location.reload();
					} else {
						alert("提交失败!");
						alert("当前订单已提交")
						location.reload();
					}
				}
			})
		}
	}


	function searchSnacks() {
		var index = $("#index").val();
		if (index!=""){
			var  dizhi="LoginIdServlet";
			$.ajax({
				url: dizhi,
				type: "post",
				data: {index: index},
				dataType: "json",
				success: function(data) {
					var tbodyStr = "";
					$(data).each(function(index, item) {
						tbodyStr += '<tr>' +
								'  <td><a onclick="upa(\'' + item.id +'\')">' + item.id + '</a></td>' +
								'  <td>' + item.timeOrder + '</td>' +
								'  <td><a href="ListDeServlet?orderNumber=' + item.orderNumber + '">' + item.orderNumber + '</a></td>' +
								'  <td>' + item.userId + '</td>' +
								'  <td>' + item.remarks + '</td>';
						if (item.helpYourself === 1) {
							tbodyStr += '<td>自取</td>';
						} else if (item.helpYourself === 0) {
							tbodyStr += '<td>外卖</td>';
						}
						if (item.payment === 1) {
							tbodyStr += '<td>余额支付</td>';
						} else if (item.payment === 0) {
							tbodyStr += '<td>微信支付</td>';
						}
						if (item.pickup === 1) {
							tbodyStr += '<td>已取餐</td>';
						} else if (item.pickup === 0) {
							tbodyStr += '<td style="color: red">未取餐</td>';
						}
						if (item.pickupTime===undefined){
							tbodyStr += '<td>' +""+ '</td>';
						}else {
							tbodyStr+='<td>' + item.pickupTime + '</td>' ;
						}
						tbodyStr += '</tr>';
					});
					$("tbody").html(tbodyStr);
				}
			});
		}else {
			location.reload();
		}
	}

	var page = 1; //页数
	var pageCount = 1;//总页数
	<!--  下页  -->
	function toNext(){
		page++;
		changePage();
	};
	<!--  上页  -->
	function toBack(){
		page--;
		changePage();
	};
	<!--  首页  -->
	function toHead(){
		page=1;
		changePage();
	};
	<!--  尾页  -->
	function toEnd(){
		page=pageCount;
		changePage();
	};

	<!--  尾页  -->
	function toPage(pageIndex){
		page=pageIndex;
		changePage();
	};

	function changePage(){
		var urlStr = "ListServlet";
		$.ajax({
			url:urlStr,
			data:{"page" : page},
			dataType:'json',
			success: function(data) {
				var tbodyStr = "";
				console.log(data);
				$(data.resultList).each(function(index,item) {
					tbodyStr += '  <tr>' +
							'        <td><a onclick="upa(\'' + item.id +'\')" href="UpdDeServlet?id='+item.id+ '">' + item.id + '</a></td>' +
							'        <td>' + item.timeOrder + '</td>' +
							'        <td><a href="ListDeServlet?orderNumber='+item.orderNumber+ '">' + item.orderNumber + '</a></td>' +
							'        <td>' + item.userId + '</td>' +
							'        <td>' + item.remarks+ '</td>';
					if (item.helpYourself === 1) {
						tbodyStr += '<td>自取</td>';
					} else if (item.helpYourself === 0) {
						tbodyStr += '<td>外卖</td>';
					}
					if (item.payment === 1) {
						tbodyStr += '<td>余额支付</td>';
					} else if (item.payment === 0) {
						tbodyStr += '<td>微信支付</td>';
					}
					if (item.pickup === 1) {
						tbodyStr += '<td>已取餐</td>';
					} else if (item.pickup === 0) {
						tbodyStr += '<td style="color: red">未取餐</td>';
					}
					if (item.pickupTime===undefined){
						tbodyStr += '<td>' +""+ '</td>';
					}else {
						tbodyStr+='<td>' + item.pickupTime + '</td>' ;
					}
					tbodyStr += '</tr>';
				});
				$("tbody").html(tbodyStr);
				pageCount=data.pageCount;
				var pageInfo="";
				if(page==1){
					pageInfo+="  <button id=\"first_page\" disabled>首页</button>\n";
				}else{
					pageInfo+="  <button id=\"first_page\" onclick='toHead()'>首页</button>\n";
					pageInfo+="\t\t<button id=\"pre_page\" onclick='toBack()'> < </button>\n" ;
				}


				for (var i =1; i <= pageCount ; i++){
					if(i==page){
						pageInfo+="\t\t<font th:text=\"${pageCount}\" id=\"page_all\" style='color:red;'>"+i+"</font>\n" ;
					}else{
						pageInfo+="\t\t<font th:text=\"${pageCount}\" id=\"page_all\" onclick='toPage("+i+")'>"+i+"</font>\n" ;
					}

				}
				if(page ==pageCount){
					pageInfo+="\t\t<button id=\"tail_page\" disabled>尾页</button>";
				} else{
					pageInfo+="\t\t<button id=\"pre_page\" onclick='toNext()'> > </button>\n" ;
					pageInfo+="\t\t<button id=\"tail_page\" onclick='toEnd()'>尾页</button>";
				}
				$("#pageDiv").html(pageInfo);
			}
		});
	};
	changePage();
</script>
</body>
</html>